package web.fabrimind.mwm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.mwm.domain.MaterialInventory;
import web.fabrimind.mwm.service.IMaterialInventoryService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;
import web.fabrimind.pm.domain.ProductionPlan;

/**
 * 物料库存Controller
 * 
 * @author ruoyi
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/mwm/inventory")
public class MaterialInventoryController extends BaseController
{
    @Autowired
    private IMaterialInventoryService materialInventoryService;

    /**
     * 查询物料库存列表
     */
    @PreAuthorize("@ss.hasPermi('mwm:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialInventory materialInventory)
    {
        startPage();
        List<MaterialInventory> list = materialInventoryService.selectMaterialInventoryList(materialInventory);
        return getDataTable(list);
    }

    /**
     * 导出物料库存列表
     */
    @PreAuthorize("@ss.hasPermi('mwm:inventory:export')")
    @Log(title = "物料库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialInventory materialInventory)
    {
        List<MaterialInventory> list = materialInventoryService.selectMaterialInventoryList(materialInventory);
        ExcelUtil<MaterialInventory> util = new ExcelUtil<MaterialInventory>(MaterialInventory.class);
        util.exportExcel(response, list, "物料库存数据");
    }

    /**
     * 获取物料库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('mwm:inventory:query')")
    @GetMapping(value = "/{inventoryId}")
    public AjaxResult getInfo(@PathVariable("inventoryId") Long inventoryId)
    {
        return success(materialInventoryService.selectMaterialInventoryByInventoryId(inventoryId));
    }

    /**
     * 新增物料库存
     */
    @PreAuthorize("@ss.hasPermi('mwm:inventory:add')")
    @Log(title = "物料库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialInventory materialInventory)
    {
        return toAjax(materialInventoryService.insertMaterialInventory(materialInventory));
    }

    /**
     * 修改物料库存
     */
    @PreAuthorize("@ss.hasPermi('mwm:inventory:edit')")
    @Log(title = "物料库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialInventory materialInventory)
    {
        return toAjax(materialInventoryService.updateMaterialInventory(materialInventory));
    }

    /**
     * 删除物料库存
     */
    @PreAuthorize("@ss.hasPermi('mwm:inventory:remove')")
    @Log(title = "物料库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inventoryIds}")
    public AjaxResult remove(@PathVariable Long[] inventoryIds)
    {
        return toAjax(materialInventoryService.deleteMaterialInventoryByInventoryIds(inventoryIds));
    }

    /**
     * 查询物料列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('mwm:material:list')")
    @GetMapping("/material/getlist")
    public AjaxResult getMaterialList(MaterialInventory materialInventory) {
        List<MaterialInventory> materialList = materialInventoryService.selectMaterialList(materialInventory);
        return AjaxResult.success(materialList);
    }


    /**
     * 查询仓库列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('mwm:warehouse:list')")
    @GetMapping("/warehouse/getlist")
    public AjaxResult getWarehouseList(MaterialInventory materialInventory) {
        List<MaterialInventory> warehouseList = materialInventoryService.selectWarehouseList(materialInventory);
        return AjaxResult.success(warehouseList);
    }


    /**
     * 查询库位列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('mwm:location:list')")
    @GetMapping("/location/getlist")
    public AjaxResult getLocationList(MaterialInventory materialInventory) {
        List<MaterialInventory> locationList = materialInventoryService.selectLocationList(materialInventory);
        return AjaxResult.success(locationList);
    }


    /**
     * 查询批次列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('mwm:batch:list')")
    @GetMapping("/batch/getlist")
    public AjaxResult getBatchList(MaterialInventory materialInventory) {
        List<MaterialInventory> batchList = materialInventoryService.selectBatchList(materialInventory);
        return AjaxResult.success(batchList);
    }




}
